package com.ts.enterprise.rest.common;


import com.ts.enterprise.common.annotation.LoginRequired;
import com.ts.enterprise.common.consts.Constant;
import com.ts.enterprise.common.response.ApiResult;
import com.ts.enterprise.common.service.CommonService;
import com.ts.enterprise.module.user.entity.Tag;
import com.ts.enterprise.module.user.query.SmsCheckQuery;
import com.ts.enterprise.module.user.query.SmsSendQuery;
import com.ts.enterprise.module.user.query.TagQuery;
import com.ts.enterprise.module.user.service.DictService;
import com.ts.enterprise.module.user.service.TagService;
import com.ts.enterprise.module.user.vo.DictResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


/**
 * @author 作者 Dean
 */
@RestController
@Api(tags = "通用公共接口")
@Slf4j
@RequestMapping(Constant.API_COMMON +"/public")
public class PublicController {

    @Autowired
    private CommonService commonService;

    @Autowired
    private DictService dictService;

    @Autowired
    private TagService tagService;

    @ApiOperation(value = "获取阿里云oss参数带签名")
    @PostMapping(value = "/ossTokenWithSign")
    public ApiResult<Map<String, String>> ossTokenWithSign(HttpServletRequest request, HttpServletResponse response) {
        return ApiResult.success(commonService.getAliOssAppTokenWithSign(request, response));
    }

    @ApiOperation(value = "发送手机验证码 5分钟有效")
    @PostMapping("/sendSmsCode")
    public ApiResult<Boolean> sendSmsCode( @Validated @RequestBody SmsSendQuery query) {
        return ApiResult.result(commonService.sendSmsCode(query.getMobile()));
    }

    @ApiOperation(value = "校验手机验证码")
    @PostMapping("/checkSmsCode")
    public ApiResult<Boolean> checkSmsCode(@Validated @RequestBody SmsCheckQuery smsCheckQuery) {
        return ApiResult.result(commonService.checkSmsCode(smsCheckQuery.getMobile(),smsCheckQuery.getSmsCode()));
    }

    @LoginRequired
    @ApiOperation(value = "查询字典", response = DictResponse.class)
    @RequestMapping(value = "/selectDictAll", method = RequestMethod.POST)
    public ApiResult<Object> selectDictAll() {
        List<DictResponse> dictResponseList = dictService.selectAll();
        return ApiResult.success(dictResponseList);
    }

    @ApiOperation(value = "查询员工标签", response = DictResponse.class)
    @PostMapping(value = "/selectTagAll")
    public ApiResult<Object> selectTag(@RequestBody TagQuery tagQuery) {
        List<Tag> tagList = tagService.listAll(tagQuery.getShowType(), tagQuery.getValueType());
        return ApiResult.success(tagList);
    }



}
